import React from "react";
import { loginApi } from "../../api";
import { useNavigate } from "react-router-dom";
import { useDispatch } from "react-redux";
import { increment } from "../../store/user/userS";
import { Form, Input, Button } from "antd-mobile";
import dayjs from "dayjs";
function Index() {
  const naviagte = useNavigate();
  const dispatch = useDispatch();
  const onFinish=async(value)=>{
    const resp=await loginApi(value)
    const {code,data,message}=resp.data
    if(code===200){
      alert(message)
      naviagte('/my')
      dispatch(increment(data))
    }else{
      alert(message)
    }
  }
  return (
    <div>
      <Form
        layout="horizontal"
        onFinish={onFinish}
        footer={
          <Button block type="submit" color="primary" size="large">
            提交
          </Button>
        }
      >
        <Form.Item
          name="username"
          label="登录"
          rules={[{ required: true, message: "账号不能为空" }]}
        >
          <Input onChange={console.log} placeholder="请输入账号" />
        </Form.Item>
        <Form.Item
          name="password"
          label="密码"
          rules={[{ required: true, message: "密码不能为空" }]}
        >
          <Input onChange={console.log} placeholder="请输入密码" />
        </Form.Item>
      </Form>
    </div>
  );
}

export default Index;
